import {baseAjax} from '../baseAjax'
import { Message } from 'element-ui'
import http, {endLoading} from '../../utils/httpRequest'

// 颜色对照表
export const accountColorList = [
  {
    name: '桃红色',
    code: 'red',
    value: '#F18686'
  },
  {
    name: '杏黄色',
    code: 'yellow',
    value: '#EA8B4B'
  },
  {
    name: '黛蓝色',
    code: 'darkBlue',
    value: '#466385'
  },
  {
    name: '群青色',
    code: 'lightGreen',
    value: '#67B4C4'
  },
  {
    name: '石绿色',
    code: 'green',
    value: '#5FB17D'
  },
  {
    name: '青莲色',
    code: 'purple',
    value: '#BE67BE'
  },
  {
    name: '深蓝色',
    code: 'deepBlue',
    value: '#6E92E9'
  }
]

// 等级ABC
export const customerLever = [
  {
    name: 'A',
    id: 1
  },
  {
    name: 'B',
    id: 2
  }, {
    name: 'C',
    id: 3
  }
]
// 资质匹配
export function matchQuali (data, success, error) {
  baseAjax('/ent/customer/quali/match', data, 'post', success, error)
}

// 导出
export function exportData (url, data, fileName = '') {
  http({
    url: http.adornUrl(url),
    method: 'post',
    data: http.adornData(data),
    responseType: 'blob',
    showLoading: true
  }).then(({data}) => {
    if (data) {
      const link = document.createElement('a')
      let blob = new Blob([data], {type: 'application/vnd.ms-excel'})
      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      let _fileName = fileName
      link.setAttribute('download', _fileName)
      link.download = _fileName // 下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    }
  })
}

// 下载
export function downloadData (url, data, fileName = '') {
  http({
    url: url,
    method: 'post',
    data: http.adornData(data),
    responseType: 'blob',
    showLoading: true
  }).then(({data}) => {
    if (data) {
      const link = document.createElement('a')
      let blob = new Blob([data], {type: 'application/vnd.ms-excel'})
      link.style.display = 'none'
      link.href = URL.createObjectURL(blob)
      let _fileName = fileName
      link.setAttribute('download', _fileName)
      link.download = _fileName // 下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    }
  }).catch(() => {
    Message.error('下载失败，请稍后重试!')
    endLoading()
  })
}

// 获取字典表
export function getDictList (data, successHandle, failHandle) {
  baseAjax('/ent/dict/value/list', data, 'post', successHandle, failHandle)
}

// 设置客户E等级设置
export function markELever (data, successHandle, failHandle) {
  baseAjax('/ent/customer/mark', data, 'post', successHandle, failHandle)
}
